import Vue from 'vue'
import vi18n from 'vue-i18n'
// import store from "../../store"
// store.commit("user/set")
Vue.use(vi18n)  // 注册 $t函数 和 $i18n语言对象
// localStorage.setItem('lang', 'zh')
// console.log(localStorage.getItem('lang'))
let locale
if(localStorage.getItem("lang")){
  locale = localStorage.getItem("lang")
} else {
  let lang = navigator.language || navigator.userLanguage  // zh-CN
  console.log(lang)
  lang = lang.substr(0, 2)
  console.log(lang)
  if(lang == "zh") {
    locale = "zh"
    localStorage.setItem("lang", "zh")
  } else {
    localStorage.setItem("lang", "en")
    locale = "en"
  }
}
const i18n = new vi18n({
  locale,  //  通过 || 逻辑写语言的优先级
  // locale: 'en', 
  messages: {
    'en': require('@/assets/lang/en.js'),
    'zh': require('@/assets/lang/zh.js'),
    'fanti': require('@/assets/lang/fanti.js'),
  }
})

export default i18n
